<template>
  <div class="app-container">
    <!-- <el-tabs v-model="taskType" type="card" @tab-click="handleClick">
      <el-tab-pane label="部门" name="10"></el-tab-pane>
      <el-tab-pane label="科室" name="20"></el-tab-pane> -->
      <!-- <el-tab-pane label="政务外网调度" name="30"></el-tab-pane>
      <el-tab-pane label="政务云调度" name="60"></el-tab-pane>
      <el-tab-pane label="地市调度" name="40"></el-tab-pane> -->
    <!-- </el-tabs> -->
    <div class="center-box">
      <div class="filter-container">
        <el-form :inline="true" class="demo-form-inline" label-position="left" label-width="70px">
          <el-form-item label="目标">
            <el-input v-model="search.mainName" placeholder="请输入目标" />
          </el-form-item>
          <!-- <el-form-item label="执行人" label-width="60px">
          <el-select v-model="search.executor" filterable remote  placeholder="请输入执行人"
            :remote-method="remoteMethod" :loading="loading">
            <el-option v-for="item in options" :key="item.userName" :label="`${item.acName}(${item.cityName})`"
              :value="item.userName">
            </el-option>
          </el-select>
        </el-form-item> -->
          <el-form-item label="目标状态" label-width="70px">
            <el-select v-model="search.taskState" placeholder="请选择" clearable>
              <el-option v-for="item, i in typeOptions" :key="i" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
            <el-button @click="reset">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="card-box">
        <div v-for="item, idx in list" :key="idx" class="card-item">
          <div class="name-box">
            <div class="type-bg"
              :class="item.taskState === 0 ? 'gray-bg' : item.taskState === 1 ? '' : item.taskState === 2 ? 'green-bg' : 'red-bg'">
              {{ item.taskState === 0 ? '待开始' : item.taskState === 1 ? '进行中' : item.taskState === 2 ? '已完成' : '已延期' }}
            </div>
            <div class="card-content">
              <div class="card-name" :title="item.mainName">{{ item.mainName || '--' }}</div>
              <div class="content-value">
                <span class="label">制定人：</span>
                <span class="value">{{ item.distributorAcName || '--' }}</span>
                <!-- <span class="label" style="margin-left: 10px;">类型：</span>
                <span class="value">{{ item.taskType == '10' ? '部门' : item.taskType == '20' ? '科室' : item.taskType ==
                  '30'
                  ? '政务外网调度': item.taskType ==
                  '60'
                  ? '政务云调度' : item.taskType ==
                    '40'
                    ? '地市调度' : '--' }}</span> -->
                <span class="label" style="margin-left: 10px;" v-if="item.taskType == '20'">科室：</span>
                <span class="value" v-if="item.taskType == '20'" :title="item.deptName">{{ item.deptName || '--' }}</span>
                 <span class="label" style="margin-left: 10px;" v-if="item.taskType == '10'">承接专项：</span>
                <span class="value" v-if="item.taskType == '10'" :title="item.specializedName">{{ item.specializedName || '--' }}</span>
              </div>
            </div>
          </div>
          <!-- <div class="task-content" title="任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述描">
          任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述任务描述描述
        </div> -->
          <div class="content-box">
            <div class="content-item"><span class="label">计划开始时间</span>{{ item.planBeginTime || '' }}</div>
            <div class="content-item"><span class="label">计划完成时间</span>{{ item.planEndTime || '--' }}</div>
            <div class="content-item"><span class="label">我的关键结果</span>{{ item.subtaskCount || 0}}
            </div>
            <div class="content-item"><span class="label">未完成关键结果</span><span
                :class="item.incompleteSubtaskCount > 0 && 'red'">{{ item.incompleteSubtaskCount || 0 }}</span></div>
            <div class="content-item"><span class="label">{{ item.taskType == '30' || item.taskType == '60'  ? '我的调度指标' : '我的本月关键结果' }}</span>{{
              item.keyResultCount ||
              0 }}
            </div>
          </div>
          <div class="bar-box">
           <div>时间进度</div>
            <div class="bg">
              <div class="bar" :style="{ width: item.timeProgress + '%' }" />
            </div>
            <div>{{ item.timeProgress ? truncateToFixed(item.timeProgress, 1) : 0 }}%</div>
          </div>
          <div class="detail-btn" @click="goDetail(item)">查看详情</div>
        </div>
        <div v-if="!list.length" class="empty-box">
          <img src="../../assets/img/empty.png" width="180" />
          <div>暂无数据</div>
        </div>
      </div>
      <pagination v-show="total > 0" :total="total" :page.sync="pagination.pageNum" :limit.sync="pagination.pageSize"
        @pagination="getPagination" />
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import { myTasks, getPersonList } from '@/api/api'
export default {
  name: 'supervisetask',
  components: { Pagination },
  data() {
    return {
      taskType: '40',
      typeOptions: [
        {
          value: '0',
          label: '待开始'
        },
        {
          value: '1',
          label: '进行中'
        },
        {
          value: '2',
          label: '已完成'
        }, {
          value: '3',
          label: '已延期'
        }
      ],
      options: [],
      search: {},
      list: [],
      total: 0,
      pagination: {
        'pageNum': 1,
        'pageSize': 20
      }
    }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.path == '/mytask/list') {
        vm.onSubmit();
      }
    });
  },
  mounted() {
    this.getMyTasks()
  },
  methods: {
    handleClick() {
      this.getMyTasks()
    },
    truncateToFixed(value, decimals) {
      const integerPart = Math.trunc(value || 0); // 获取整数部分
      const decimalPart = value - integerPart; // 获取小数部分
      const factor = Math.pow(10, decimals);
      const truncatedDecimalPart = decimalPart < 0 ? Math.ceil(decimalPart * factor) / factor : Math.floor(decimalPart * factor) / factor; // 根据正负选择向上或向下截断
      return integerPart + truncatedDecimalPart; // 组合整数部分和小数部分
    },
    getMyTasks() {
      myTasks({
        page: this.pagination.pageNum, size: this.pagination.pageSize, ...this.search, currentUser: localStorage.getItem('userName'),
        taskType: this.taskType
      }).then(res => {
        this.total = res.data.total || 0;
        this.list = res?.data?.data || [];
      })
    },
    getPerson(acName) {
      this.loading = false;
      getPersonList({ acName }).then(res => {
        this.options = res || []
      })
    },
    getPagination(pagination) {
      this.pagination = pagination
      this.getMyTasks()
    },
    onSubmit() {
      this.pagination = {
        "pageNum": 1,
        "pageSize": 20
      }
      this.getMyTasks()
    },
    reset() {
      this.search = {
        // taskType: '20'
      }
      this.personList = []
      this.onSubmit()
    },
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        this.getPerson(query.toLowerCase())
      } else {
        this.options = [];
      }
    },
    goDetail(row) {
      this.$router.push({
        path: row.taskType != '30' && row.taskType != '60' ? `/work/detail/${row.mainId}` : `/network/net/cloudDetail/${row.mainId}`
      })
    },
  }
}
</script>
<style lang="scss" scoped>
::v-deep .el-form-item {
  margin-bottom: 10px;
}

.filter-container {
  padding-bottom: 3px;
}

.app-container {
  overflow-y: auto;
  height: calc(100vh - 86px);
  padding: 0;
}

.pagination-container {
  padding: 0 16px;
  margin-top: 0;
}

.card-box {
  display: flex;
  flex-wrap: wrap;
  max-height: calc(100vh - 225px);
  overflow-y: auto;

  .card-item {
    width: calc(25% - 16px);
    margin: 0 8px;
    height: 250px;
    border: 1px solid #ddd;
    margin-bottom: 16px;
    border-radius: 7px;
    overflow: hidden;
    box-shadow: 0 0 10px #dedede;
    position: relative;
  }

  @media (max-width: 1845px) {
    .card-item {
      width: calc(33.3% - 16px);
    }
  }

  @media (max-width: 1500px) {
    .card-item {
      width: calc(50% - 16px);
    }
  }

  @media (max-width: 1100px) {
    .card-item {
      width: 100%;
    }
  }

  .name-box {
    height: 94px;
    background: rgb(238, 247, 255);
    padding: 10px 12px;
    display: flex;
    flex-wrap: wrap;

    .card-content {
      width: calc(100% - 90px);
    }

    .card-name {
      font-size: 18px;
      color: #222;
      font-weight: bold;
      margin-left: 20px;
      margin-bottom: 5px;
      width: 100%;
      overflow: hidden;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
    }

    .content-value {
      font-size: 14px;
      color: #666;
      margin-left: 20px;
      line-height: 24px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 100%;
      .label {
        color: #555;
        font-weight: bold;
      }
    }
  }

  .task-content {
    padding: 10px 16px 5px;
    font-size: 14px;
    line-height: 22px;
    color: #333;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
}

/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
.card-box::-webkit-scrollbar {
  width: 8px;
  height: 0px;
  background-color: #F5F5F5;
}

/*定义滚动条轨道 内阴影+圆角*/
.card-box::-webkit-scrollbar-track {
  border-radius: 10px;
  background-color: #F5F5F5;
}

/*定义滑块 内阴影+圆角*/
.card-box::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background-color: #ccc;
}

.type-bg {
  color: #fff;
  width: 74px;
  height: 74px;
  background: linear-gradient(to bottom, #4dfff8, #3b71e9);
  // background: linear-gradient(to bottom, #afd1ff, #3b71e9);
  border-radius: 74px;
  text-align: center;
  line-height: 74px;
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
}

.gray-bg {
  background: linear-gradient(to bottom, #e7e7e7, #a4a5a5);
}

.red-bg {
  background: linear-gradient(to bottom, #ffc770, #e51818);
}

.green-bg {
  background: linear-gradient(to bottom, #42ff8f, #0d9b11);
}

.content-box {
  padding: 0 16px;
  font-size: 14px;
  color: #333;
  font-weight: bold;
  display: flex;
  flex-wrap: wrap;
  margin-top: 10px;

  .content-item {
    width: 50%;
    line-height: 24px;
  }

  .label {
    margin-right: 8px;
    display: inline-block;
    color: #666;
    font-weight: 500;
  }

  .red {
    color: #eb1c1c;
  }
}

.bg {
  width: calc(100% - 125px);
  height: 10px;
  background: #d4dffe;
  border-radius: 10px;
  margin: 6px 12px 0;

  .bar {
    height: 10px;
    border-radius: 10px;
    background: linear-gradient(to right, #8ef5fb, #30b3ff);
  }
}

.bar-box {
  width: 100%;
  padding: 5px 16px;
  display: flex;
  font-size: 14px;
}

.detail-btn {
  width: 100%;
  height: 34px;
  text-align: center;
  line-height: 34px;
  position: absolute;
  bottom: 0;
  // background: #eef7ff;
  font-size: 14px;
  cursor: pointer;
  border-top: 1px solid #ddd;

  &:hover {
    color: #46a6ff;
  }
}

.empty-box {
  text-align: center;
  color: #999;
  line-height: 40px;
  margin-top: 100px;
  width: 100%;
}

.center-box {
  padding: 16px 16px 10px;
}

::v-deep .el-tabs--card>.el-tabs__header .el-tabs__item.is-active {
  font-weight: bold;
}

::v-deep .el-tabs__item {
  height: 30px;
  line-height: 30px;
}
</style>
